﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using WorkItemAnalyser.Core.Assertions;
using WorkItemAnalyser.Core.Parsers;

namespace WorkItemAnalyser.Test.ParserTests
{
    [TestClass]
    public class TextFieldAssertionParserTests
    {
        [TestMethod]
        public void TextFieldAssertionParser_ParseAssertion_ShouldReturnNullForEmptyString()
        {
            //Arrange 
            var parser = new TextFieldAssertionParser();

            //Act
            var assertion = parser.ParseAssertion("");

            //Assert
            Assert.IsNull(assertion);
        }
        
        [TestMethod]
        public void TextFieldAssertionParser_ParseAssertion_ShouldReturnNullForInvalidString()
        {
            //Arrange 
            var parser = new TextFieldAssertionParser();

            //Act
            var assertion = parser.ParseAssertion("some invalid rule text");

            //Assert
            Assert.IsNull(assertion);
        }

        [TestMethod]
        public void TextFieldAssertionParser_ParseAssertion_ShouldReturnNullForPartiallyValidString()
        {
            //Arrange 
            var parser = new TextFieldAssertionParser();

            //Act
            var assertion = parser.ParseAssertion("field should blah blah");

            //Assert
            Assert.IsNull(assertion);
        }

        [TestMethod]
        public void TextFieldAssertionParser_ParseAssertion_ShouldReturnValidAssertionForValidSimpleString()
        {
            //Arrange 
            var parser = new TextFieldAssertionParser();

            //Act 
            var assertion = parser.ParseAssertion("the status should be closed");
            var fieldAssertion = assertion as FieldAssertion;

            //Assert
            Assert.IsNotNull(fieldAssertion);
            Assert.AreEqual(fieldAssertion.FieldName, "status");
            Assert.AreEqual(fieldAssertion.FieldValue, "closed");
        }

        [TestMethod]
        public void TextFieldAssertionParser_ParseAssertion_ShouldReturnValidAssertionForValidSpacedString()
        {
            //Arrange 
            var parser = new TextFieldAssertionParser();

            //Act 
            var assertion = parser.ParseAssertion("the iteration path should be //WICSA/Iteration 1");
            var fieldAssertion = assertion as FieldAssertion;

            //Assert
            Assert.IsNotNull(fieldAssertion);
            Assert.AreEqual(fieldAssertion.FieldName, "iteration path");
            Assert.AreEqual(fieldAssertion.FieldValue, "//WICSA/Iteration 1");
        }

        [TestMethod]
        public void TextFieldAssertionParser_ParseAssertion_ShouldReturnValidAssertionForSimpleAdditionalAssertionString()
        {
            //Arrange 
            var parser = new TextFieldAssertionParser();

            //Act 
            var assertion = parser.ParseAssertion("and the status should be closed");
            var fieldAssertion = assertion as FieldAssertion;

            //Assert
            Assert.IsNotNull(fieldAssertion);
            Assert.AreEqual(fieldAssertion.FieldName, "status");
            Assert.AreEqual(fieldAssertion.FieldValue, "closed");
        }

        [TestMethod]
        public void TextFieldAssertionParser_ParseAssertion_ShouldReturnValidAssertionForSpacedAdditionalAssertionString()
        {
            //Arrange 
            var parser = new TextFieldAssertionParser();

            //Act 
            var assertion = parser.ParseAssertion("and the iteration path should be //WICSA/Iteration 1");
            var fieldAssertion = assertion as FieldAssertion;

            //Assert
            Assert.IsNotNull(fieldAssertion);
            Assert.AreEqual(fieldAssertion.FieldName, "iteration path");
            Assert.AreEqual(fieldAssertion.FieldValue, "//WICSA/Iteration 1");
        }
    }
}
